﻿@{
    ViewData["Title"] = "Home Page";
}


<ul class="form-group" id="messagesListUl" style="margin-bottom:20px">
    <li>Message List</li>
</ul>

<form>
    <div class="form-group">
        <label for="username">姓名:</label>
        <input type="text" class="form-control" id="username" name="username">
    </div>
    <div class="form-group">
        <label for="msgcontent">内容:</label>
        <textarea rows="5" cols="20" id="msgcontent" name="msgcontent" class="form-control"></textarea>
    </div>
    <input type="button" onclick="btnSendMsg()" value="广播消息">
</form>


<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/signalr/dist/browser/signalr.js"></script>
<script src="~/js/mySignalR.js"></script>
<script type="text/javascript">


    //发送广播消息
    function btnSendMsg(){
        var username = $.trim($("#username").val());
        var msgcontent = $.trim($("#msgcontent").val());
        var msgObj={};
        msgObj.name=username;
        msgObj.message=msgcontent;
        var jsonstr=JSON.stringify(msgObj);//对象转json串
        console.log(jsonstr);
        signalr_connection.invoke("SendMessage", jsonstr).catch(err => console.error("发送失败："+err.toString()));
    }

</script>